import axios from 'axios';
const baseUrl = '/api'
class HttpRequest{
    constructor(baseUrl) {
        this.baseUrl = baseUrl
        // this.queue = {}
        // this.pending = []
        // this.maxNum = 5 // 最多并发请求数
        // this.createQueue()
  
      
    }
    getInsideConfig() {
        const config = {
            baseURL: this.baseUrl,
            headers: {
                // 'Content-Type': 'application/json',
                // 'Authorization': `Bearer ${localStorage.getItem('token')}`,
            },
            // timeout: 10000,
           
        }
        return config
    }
    interception(indtance) {
        //请求拦截器
        indtance.interceptors.request.use(config => {
            // const token = localStorage.getItem('token')
            // if (token) {
            //     config.headers['Authorization'] = `Bearer ${token}`
            // }
            return config
        }, error => {
            return Promise.reject(error)
        })
      //响应拦截器
        indtance.interceptors.response.use(response => {
            // const { status } = response.data
            // if (status === 401) {
            //     // token 过期或者无效，跳转到登录页
            //     localStorage.removeItem('token')
            //     router.push('/login')
            // }
            return response.data
        }, error => {
            return Promise.reject(error)
        })
    }
    request(options) {
        options = { ...this.getInsideConfig, ...options }
        const instance = axios.create()
        this.interception(instance)
        return instance(options)
    }
}

export default new HttpRequest(baseUrl)